//
//  BLClothMangeViewController.m
//  blanket
//
//  Created by Mac on 2017/12/6.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "BLWathClosthHomeViewController.h"
#import "BLClothAlertViewController.h"
#import "BLCloseChaneViewController.h"
#import "BLRepertoryViewController.h"
#import "BLClosthWashViewController.h"
#import "BLInReportCheckViewController.h"
@interface BLWathClosthHomeViewController ()
@property(nonatomic, strong) STLabel                     *percetLabel;
@property(nonatomic, strong) STLabel                     *desLabel;

@end

@implementation BLWathClosthHomeViewController
#pragma mark --vc 生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"布草洗涤";
    self.tableView.backgroundColor = [UIColor whiteColor];
     [self configSubView];
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}
#pragma mark --subView
- (void)configSubView{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    header.backgroundColor = [UIColor whiteColor];
    __weak typeof(self) weakSelf =  self;
    STButton * lookButton = [[STButton alloc] initWithFrame:CGRectMake(30, 30, UIScreenWidth - 60, 60)
                                                      title:@"查看入库复核数据"
                                                 titleColor:[UIColor whiteColor]
                                                  titleFont:16
                                               cornerRadius:5
                                            backgroundColor:BL_BlueBackGroundColor
                                            backgroundImage:nil
                                                      image:nil];
    lookButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [lookButton setClicAction:^(UIButton *sender) {
        [weakSelf.navigationController pushViewController:BLInReportCheckViewController.new animated:YES];
    }];
    [header addSubview:lookButton];
    
    
    STButton * washButton = [[STButton alloc] initWithFrame:CGRectMake(30, lookButton.bottom + 40, UIScreenWidth - 60, 60)
                                                        title:@"布草洗涤"
                                                   titleColor:BL_BlueBackGroundColor
                                                    titleFont:16
                                                 cornerRadius:5
                                              backgroundColor:[UIColor whiteColor]
                                              backgroundImage:nil
                                                        image:nil];
    washButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [header addSubview:washButton];
    [washButton st_setBorderWith:1 borderColor:BL_BlueBackGroundColor cornerRadius:5];
    [washButton setClicAction:^(UIButton *sender) {
        [weakSelf.navigationController pushViewController:BLClosthWashViewController.new animated:YES];
    }];
    [header addSubview:lookButton];
    header.height = washButton.bottom + 100;
    
    self.tableView.tableHeaderView = header;
    

}
#pragma mark --Action Method
- (void)onSelectedAddButton{
    BLCloseChaneViewController * vc = [BLCloseChaneViewController new];
    vc.isClothAdd = YES;
    vc.percetAlert = self.percetLabel.text;
    vc.desAlert = self.desLabel.text;
    vc.desColror = self.desLabel.textColor;
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)onSelectedReduceButton{
    BLCloseChaneViewController * vc = [BLCloseChaneViewController new];
    vc.isClothAdd = NO;
    vc.percetAlert = self.percetLabel.text;
    vc.desAlert = self.desLabel.text;
    vc.desColror = self.desLabel.textColor;
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark --NetWork Method
- (void)sendNormalInfoRequest{
    
    NSMutableDictionary * dic = [NSMutableDictionary new];
    [dic setObject:debugToken forKey:@"token"];
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php/Api/Basics/reckon_linen"];
    if ([STUserManger defult].userID.length) {
        [dic setObject:[STUserManger defult].userID forKey:@"uid"];
    }
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 NSDictionary * dataDic =  responseObject[@"data"];
                                                 [self configSubView];
                                                 if ([dataDic.allKeys containsObject:@"int"]) {
                                                     NSString * percent = dataDic[@"int"];
                                                     NSString * percetAlert = [NSString stringWithFormat:@"当前闲置布草占比%@",percent];
                                                     self.percetLabel.text = percetAlert;
                                                 }
                                                 if ([dataDic.allKeys containsObject:@"reckon_linen"]) {
                                                     NSString * reckon_linen = dataDic[@"reckon_linen"];
                                                     self.desLabel.text = reckon_linen;
                                                     if ([reckon_linen isEqualToString:@"紧急"]) {
                                                         self.desLabel.textColor = FlatRed;
                                                     }
                                                 }
                                                 //展示描述 只展示一次
                                                 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                                                     static dispatch_once_t onceToken;
                                                     dispatch_once(&onceToken, ^{
                                                         BLClothAlertViewController * vc = [BLClothAlertViewController new];
                                                         if ([dataDic.allKeys containsObject:@"msg"]) {
                                                             NSString * msg = dataDic[@"msg"];
                                                             vc.desString = msg;
                                                         }
                                                         
                                                         [self presentViewController:vc animated:NO completion:nil];
                                                     });
                                                 });
                                                 
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [self.tableView.mj_header endRefreshing];
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}
@end
